#include <cstdio>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <cstdlib>
#include <unistd.h>
#include <cerrno>
#include <cstring>
#include <thread>
#include <csignal>
#include <eigen3/Eigen/Eigen>

#include <param.h>

//使用control中的全局变量
extern std::atomic<bool> THREAD_ALL_RUN;

void sigint_handler(const int sig) {
    printf("\n捕获到信号 SIGINT(%d)，正在退出...\n", sig);
    THREAD_ALL_RUN=false;
    std::cout << "Close ......" << std::endl;
    sleep(1);  // 休眠1s等待其他线程结束
    exit(sig);
}



int main() {
    signal(SIGINT, sigint_handler);  // 获取ctrl+C信号，也是回调机制

    //多线程打开主要程序
    hitcrt::Control control;
    std::thread thread1(&hitcrt::Control::run,&control);
    std::thread thread2(&hitcrt::Control::detect,&control);
    std::thread thread3(&hitcrt::Control::show,&control);
    thread1.join();
    thread2.join();
    thread3.join();

    while (THREAD_ALL_RUN) {
        sleep(1);
    }

    sleep(1);
    std::cout << "Main Off" << std::endl;
    return 0;
}
